package wickethub.repository;

import java.util.List;

import wickethub.data.Indexer;
import wickethub.domain.Resource;

import com.google.inject.Inject;
import com.wideplay.warp.persist.Transactional;

public class ResourceRepositoryImpl extends RepositoryImpl<Resource> implements ResourceRepository {
	
	@Inject private Indexer indexer;
	
	@SuppressWarnings("unchecked")
	public List<Resource> findAllRecentResources() {
		return getEmp().createQuery("select r from Resource r order by r.lastUpdated desc").getResultList();		
	}
	
	@Transactional @Override
	public void save(Resource resource) {
		super.save(resource);
		indexer.index(resource);
	}
	
}